package socket;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author DBX
 * @effect
 * @date 2021/8/31 0031 - 20:29
 */
public class Client2 {
    private Socket socket;

    public Client2() {
        try {
            socket = new Socket("localhost",8088);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    PrintWriter pw ;
    public void start(){
        try {
            pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(),"UTF-8")),true);
            Scanner sc = new Scanner(System.in);
            String message = null;
            while (!"exit".equals(message)){
                message = sc.nextLine();
                pw.println(message);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            pw.close();
            try {
                socket.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        Client2 c2 = new Client2();
        c2.start();
    }
}
